<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="dateInfo">
        <el-date-picker clearable v-model="queryParams.dateInfo" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择日期" :default-value="getDefaultDate()">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable filterable>
          <el-option label="成功" value="SUCCESS"></el-option>
          <el-option label="失败" value="FAILED"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="机构ID" prop="infoId">
        <el-input v-model="queryParams.infoId" placeholder="请输入机构ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="机构名称" prop="infoName">
        <el-input v-model="queryParams.infoName" placeholder="请输入机构名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="机构类型" prop="infoType">
        <el-select v-model="queryParams.infoType" placeholder="请选择类型" clearable @change="handleQuery">
          <el-option label="CRM" value="CRM"></el-option>
          <el-option label="API" value="API"></el-option>
          <el-option label="APIB" value="APIB"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pushList" >
      <el-table-column label="日期" align="center" prop="dateInfo" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dateInfo, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="渠道信息" align="center">
        <template slot-scope="scope">
          <div>
            <p>[{{ scope.row.channelCode }}] {{ scope.row.channelName }}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status" >
        <template slot-scope="scope">
             {{ scope.row.status }} | {{ scope.row.message }}
        </template>
      </el-table-column>
    
      <el-table-column label="机构信息" align="center">
        <template slot-scope="scope">
          <div>
            <p>{{ scope.row.infoName }} [{{ scope.row.infoId }}] [{{ scope.row.infoType }}] </p>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="任务ID/推送价格/数据成本" align="center" prop="taskId" >
      <template slot-scope="scope">
            {{ scope.row.taskId }} / ¥：{{ scope.row.priceAmount }} / ¥：{{ scope.row.baseAmount }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" >
       <template slot-scope="scope">
          {{ parseTime(scope.row.createTime) }}
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

  </div>
</template>

<script>
import { listBaseInfo1 } from "@/api/source/channelData";
import { baseInfoExtData } from "@/api/source/baseInfo";
export default {
  name: "Push",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 线索推送结果表格数据
      pushList: [],
      extData: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dateInfo: this.getDefaultDate(),
        channelCode: null,
        channelName: null,
        dataId: null,
        orderNo: null,
        orderItemNo: null,
        status: null,
        settleStatus: null,
        infoId: null,
        infoName: null,
        infoType: null,
        taskId: null,
        priceAmount: null,
        noticeFlag: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getOptions();
  },
  watch: {
    $route() {
      this.getList()
    }
  },
  methods: {
    /** 查询线索推送结果列表 */
    getList() {
      this.loading = true;
      const channelCode = this.$route.query.channelCode;
      this.queryParams.channelCode = channelCode;
      listBaseInfo1(this.queryParams).then(response => {
        this.pushList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getDefaultDate() {
      // 获取当天日期，并以 yyyy-MM-dd 格式返回
      const today = new Date();
      const year = today.getFullYear();
      const month = String(today.getMonth() + 1).padStart(2, '0');
      const day = String(today.getDate()).padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dateInfo: null,
        channelCode: null,
        channelName: null,
        dataId: null,
        orderNo: null,
        orderItemNo: null,
        status: null,
        settleStatus: null,
        infoId: null,
        infoName: null,
        infoType: null,
        taskId: null,
        priceAmount: null,
        noticeFlag: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getOptions() {
      baseInfoExtData().then((response) => {
        this.extData = response.data;
      });
    },
  }
};
</script>
